//
//  DayReportListTableViewCell.swift
//  BellManage
//
//  Created by Bestsch on 16/4/14.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class DayReportListTableViewCell: UITableViewCell {

    var timeLabel,titleLabel,label,contentLabel: UILabel!
    var icon: UIImageView!
    var line: UIView!
    var view: UIView!
    var lookLabel: UILabel!
    
    var dic: JSON!
    
    init(dictionary: JSON, reuseIdentifier: String?) {
        
        self.dic = dictionary
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: reuseIdentifier)
        self.contentView.backgroundColor = UIColor.init(hexString: "f6f6f6", alpha: 1)
        InitViews()
    }
    
    func InitViews(){
        timeLabel = UILabel.init(frame: CGRect.zero)
        timeLabel.textColor = UIColor.init(hexString: "9b9b9b", alpha: 1)
        timeLabel.font = UIFont.systemFont(ofSize: 14)
        timeLabel.textAlignment = NSTextAlignment.center
        
        icon = UIImageView.init(frame: CGRect.zero)
        icon.contentMode = UIViewContentMode.scaleAspectFit
        
        label = UILabel.init(frame: CGRect.zero)
        label.textColor = UIColor.white
        label.backgroundColor = barColor
        label.font = UIFont.systemFont(ofSize: 16)
        label.text = "  管理日报"
        
        view = UIView.init(frame: CGRect.zero)
        view.backgroundColor = UIColor.white
        
        titleLabel = UILabel.init(frame: CGRect.zero)
        titleLabel.textColor = UIColor.darkGray
        titleLabel.font = UIFont.boldSystemFont(ofSize: 14)
        titleLabel.backgroundColor = UIColor.white
        
        contentLabel = UILabel.init(frame: CGRect.zero)
        contentLabel.numberOfLines = 0
        contentLabel.textColor = UIColor.darkGray
        contentLabel.font = UIFont.boldSystemFont(ofSize: 14)
        contentLabel.backgroundColor = UIColor.white
        
        line = UIView.init(frame: CGRect.zero)
        line.backgroundColor = UIColor.init(hexString: "eeeeee", alpha: 1)
        
        lookLabel = UILabel.init(frame: CGRect.zero)
        lookLabel.font = UIFont.systemFont(ofSize: 14)
        lookLabel.textColor = UIColor.init(hexString: "9b9b9b", alpha: 1)
        lookLabel.text = "查看详情"
        
        let imageView: UIImageView = UIImageView.init(image: UIImage.init(named: "jtt"))
        
        self.contentView.addSubview(timeLabel)
        self.contentView.addSubview(icon)
        self.contentView.addSubview(label)
        self.contentView.addSubview(view)
        self.contentView.addSubview(titleLabel)
        self.contentView.addSubview(contentLabel)
        self.contentView.addSubview(line)
        self.contentView.addSubview(lookLabel)
        lookLabel.addSubview(imageView)
        
        let useNum = dic["useNum"].stringValue //昨日使用人数
        
        let fwcon = dic["fwcon"].stringValue//昨日访问量
        let strper = dic["strper"].stringValue//活跃率
        let fampracon = dic["fampracon"].stringValue//家长点赞数
        let famrecon = dic["famrecon"].stringValue//家长评论数
        let userpracon = dic["userpracon"].stringValue//所有点赞数
        let userRecon = dic["userRecon"].stringValue//所有评论数
        var edittime = dic["edittime"].stringValue
        
        let classactcon = dic["classactcon"].intValue//学校当日班级活动发布的数量
        let honorcon = dic["honorcon"].intValue//学校当日班级荣誉发布数量
        let anncon = dic["AnnCon"].intValue//学校当日班级通知发布数量
        let growthcon = dic["GrowthCon"].intValue//学校当日成长记录发布数量
        let leavecon = dic["LeaveCon"].intValue//学校当日请假数量
        let attCon = dic["attcon"].intValue//学校考勤数
        let HomWorkCon = dic["HomWorkCon"].intValue //学校当日作业数量
        
        let count = classactcon + honorcon + anncon + growthcon + leavecon + HomWorkCon + attCon
        
        let content = "访问量\(fwcon)次，访问人数\(useNum)人，活跃率\(strper)%，家长点赞\(fampracon)次，评论\(famrecon)次，总点赞\(userpracon)次，评论\(userRecon)次，总发布数量\(count)个。"
        
        edittime = edittime.components(separatedBy: "T")[0]
        timeLabel.text = edittime
        contentLabel.text = content
        icon.image = logo
        titleLabel.text = "\(edittime)管理日报"
        
        timeLabel.frame = CGRect(x: 0, y: 0, width: screenW, height: 40)
        
        icon.frame = CGRect(x: 10, y: timeLabel.frame.maxY, width: 40, height: 50)
//        icon.layer.cornerRadius = 20
//        icon.layer.masksToBounds = true
        
        label.frame = CGRect(x: icon.frame.maxX+10, y: timeLabel.frame.maxY, width: screenW - 90, height: 35)
        let maskPath = UIBezierPath.init(roundedRect: label.bounds, byRoundingCorners: [UIRectCorner.topLeft, UIRectCorner.topRight] , cornerRadii: CGSize(width: 4, height: 4))
        let maskLayer = CAShapeLayer.init()
        maskLayer.frame = label.bounds
        maskLayer.path = maskPath.cgPath
        label.layer.mask = maskLayer
        
        view.frame = CGRect(x: icon.frame.maxX + 10, y: label.frame.maxY, width: screenW - 90, height: 40 + getLabelHeight(content, font: UIFont.boldSystemFont(ofSize: 14) , wigth: screenW - 110) + 10 + 41)
        let maskPath1 = UIBezierPath.init(roundedRect: view.bounds, byRoundingCorners: [UIRectCorner.bottomLeft, UIRectCorner.bottomRight] , cornerRadii: CGSize(width: 4, height: 4))
        let maskLayer1 = CAShapeLayer.init()
        maskLayer1.frame = view.bounds
        maskLayer1.path = maskPath1.cgPath
        view.layer.mask = maskLayer1
        
        titleLabel.frame = CGRect(x: icon.frame.maxX + 20 , y: label.frame.maxY, width: screenW - 110, height: 35)
        
        contentLabel.frame = CGRect(x: icon.frame.maxX + 20, y: titleLabel.frame.maxY, width: screenW - 110, height: getLabelHeight(content, font: UIFont.boldSystemFont(ofSize: 14) , wigth: screenW - 110)+10)
        line.frame = CGRect(x: icon.frame.maxX + 20, y: contentLabel.frame.maxY+5, width: screenW - 110, height: 1)
        lookLabel.frame = CGRect(x: icon.frame.maxX + 20, y: line.frame.maxY, width: screenW - 110, height: 40)
        imageView.frame = CGRect(x: lookLabel.frame.width-9, y: 12.5, width: 9, height: 15)
        
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
